/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.cef.generator.coreGenerator.base.entitygen.property;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.inspur.edp.caf.generator.baseInfo.AnnotationInfo;
import com.inspur.edp.caf.generator.baseInfo.AnnotationType;
import com.inspur.edp.caf.generator.baseInfo.TypeInfo;
import com.inspur.edp.caf.generator.property.ClassPropertyGenerator;
import com.inspur.edp.caf.generator.utils.ExpressionUtils;
import com.inspur.edp.cef.gencommon.CefPropertyInfo;
import com.inspur.edp.cef.generator.common.MediatePropertyInfo;
import com.inspur.edp.cef.spi.entity.INestedConfig;
import com.inspur.edp.cef.spi.jsonser.base.StringUtils;
import java.util.ArrayList;
import org.eclipse.jdt.core.dom.Modifier;

public class DataTypePropGenerator extends ClassPropertyGenerator {


  ///#region 属性与初始化
  private MediatePropertyInfo privatePropertyInfo;
  private String privateFieldName;

  public DataTypePropGenerator(MediatePropertyInfo propertyInfo,
      String fieldName) {
    privatePropertyInfo = propertyInfo;
    privateFieldName = fieldName;
  }

  protected final MediatePropertyInfo getPropertyInfo() {
    return privatePropertyInfo;
  }

  public final String getFieldName() {
    return privateFieldName;
  }

  @Override
  protected TypeInfo getPropertyType() {
    return privatePropertyInfo.getReturnType();
  }

  @Override
  protected String getPropertyName() {
    return privatePropertyInfo.getPropertyName();
  }

  @Override
  protected ArrayList<Modifier.ModifierKeyword> getSetterAccessModifier() {
    ArrayList<Modifier.ModifierKeyword> list = new ArrayList<>();
    list.add(Modifier.ModifierKeyword.PUBLIC_KEYWORD);
    return list;
  }

  @Override
  protected ArrayList<Modifier.ModifierKeyword> getGetterAccessModifier() {
    ArrayList<Modifier.ModifierKeyword> list = new ArrayList<>();
    list.add(Modifier.ModifierKeyword.PUBLIC_KEYWORD);
    return list;
  }

  @Override
  protected ArrayList<AnnotationInfo> getGetterAttributeList() {
    ArrayList<AnnotationInfo> list = super.getGetterAttributeList();
    if (list == null) {
      list = new ArrayList<>();
    }

    AnnotationInfo annotationInfo = new AnnotationInfo();
    annotationInfo.setAnnotationType(AnnotationType.SingleMember);
    annotationInfo.setTypeInfo(new TypeInfo(JsonProperty.class));
    annotationInfo.setSingleParam(ExpressionUtils.getStringLiteral(
        ast, StringUtils.toCamelCase(getPropertyName())
    ));
    list.add(annotationInfo);
    return list;
  }
  //Java版临时注释
//	@Override
//	protected java.util.ArrayList<AttributeInfo> getAttributeList()
//	{
//		java.util.ArrayList<AttributeInfo> list = super.getAttributeList();

//		var assoUdtAttribute = getPropertyInfo().getCustomAttribute(AssoUdtAtrribute.class);
//		if (assoUdtAttribute != null)
//		{
//			if (list == null)
//			{
//				list = new java.util.ArrayList<AttributeInfo>();
//			}
//			AttributeInfo tempVar = new AttributeInfo();
//			tempVar.AttributeName = JsonIgnoreAttribute.class.FullName;
//			list.add(tempVar);
//		}
//		return list;
//	}

}
